import {onMounted, onUnmounted, reactive} from "vue";

export default function() {
    // 实现鼠标打点的数据
    let point = reactive({
        x: 0,
        y: 0,
    })

    // 实现鼠标打点的方法
    function savePoint(event){
        point.x = event.pageX
        point.y = event.pageY
        console.log(point)
    }
    //通过组合式API的形式去使用生命周期钩子
    onMounted(()=>{
        console.log('---onMounted---')
        window.addEventListener('click', savePoint)
    })
    onUnmounted(()=>{
        console.log('---onUnmounted---')
        window.removeEventListener('click', savePoint)
    })

    return point;
}
